﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:Framework.UI.Controls"
                    xmlns:metro="http://schemas.codeplex.com/elysium"
                    xmlns:params="http://schemas.codeplex.com/elysium/params"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/TextBlock.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type controls:LoadingContent}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="ContentOpacity" Value="0.2"/>
        <Setter Property="Fill" Value="{StaticResource AccentBrush}"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:LoadingContent}">
                    <Grid>

                        <ContentPresenter x:Name="ContentElement" 
                                          Content="{TemplateBinding Content}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                          HorizontalAlignment="Stretch"
                                          IsHitTestVisible="{TemplateBinding IsContentLoaded}"
                                          Opacity="{TemplateBinding ContentOpacity}"
                                          VerticalAlignment="Stretch"/>

                        <controls:BorderFix x:Name="LoadingElement" 
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <metro:ProgressBar x:Name="ProgressBar" 
                                                       Grid.Row="1"
                                                       Foreground="{TemplateBinding Fill}"
                                                       Margin="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay}"/>

                                <TextBlock Grid.Row="2"  
                                               Foreground="{TemplateBinding Foreground}" 
                                               HorizontalAlignment="Center"
                                               Style="{StaticResource HeaderTextStyle}"
                                               Text="{TemplateBinding Header}"/>

                            </Grid>
                        </controls:BorderFix>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Loaded">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         To="1"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ProgressBar"
                                                                       Storyboard.TargetProperty="State">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <metro:ProgressState>Normal</metro:ProgressState>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unloaded">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         From="1"/>
                                        <DoubleAnimation Storyboard.TargetName="LoadingElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         From="0"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ProgressBar"
                                                                       Storyboard.TargetProperty="State">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <metro:ProgressState>Busy</metro:ProgressState>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="RingLoadingContentStyle" TargetType="{x:Type controls:LoadingContent}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="ContentOpacity" Value="0.2"/>
        <Setter Property="Fill" Value="{StaticResource AccentBrush}"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:LoadingContent}">
                    <Grid>

                        <ContentPresenter x:Name="ContentElement" 
                                          Content="{TemplateBinding Content}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                          HorizontalAlignment="Stretch"
                                          IsHitTestVisible="{TemplateBinding IsContentLoaded}"
                                          Opacity="{TemplateBinding ContentOpacity}"
                                          VerticalAlignment="Stretch"/>

                        <controls:BorderFix x:Name="LoadingElement" 
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <metro:ProgressRing x:Name="ProgressBar" 
                                                        Grid.Row="1"
                                                        Foreground="{TemplateBinding Fill}"
                                                        Height="50"
                                                        Margin="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay}"/>

                                <TextBlock Grid.Row="2"  
                                               Foreground="{TemplateBinding Foreground}" 
                                               HorizontalAlignment="Center"
                                               Style="{StaticResource HeaderTextStyle}"
                                               Text="{TemplateBinding Header}"/>

                            </Grid>
                        </controls:BorderFix>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Loaded">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         To="1"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ProgressBar"
                                                                       Storyboard.TargetProperty="State">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <metro:ProgressState>Normal</metro:ProgressState>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unloaded">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         From="1"/>
                                        <DoubleAnimation Storyboard.TargetName="LoadingElement"
                                                         Storyboard.TargetProperty="Opacity"
                                                         BeginTime="00:00:00"
                                                         Duration="00:00:00.5"
                                                         From="0"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ProgressBar"
                                                                       Storyboard.TargetProperty="State">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <metro:ProgressState>Busy</metro:ProgressState>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>